<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="isShow=!isShow">{{isShow?'隐藏':'显示'}}</button>
    <home-page v-if="isShow"></home-page>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data(){
        return {
          isShow: true
        }
      }
    })
    const HomePage = {
      template: `
        <div>
          <h2>首页</h2>  
          <button @click="addArr">按钮</button>
          <ul ref="oul">
            <li v-for="item in arr" :key="item">
              {{ item }}  
            </li>  
          </ul>
        </div>
      `,
      data(){
        return {
          arr: [1,2,3,4]
        }
      },
      methods: {
        addArr(){
          this.arr.push(this.arr.length+1);
          console.log(this.$refs.oul.children, 111);
          this.$nextTick(() => {
            console.log(this.$refs.oul.children, 333);
          })
        }
      },
      beforeCreate(){
        console.log('beforeCreate触发');
      
      },
      created(){
        console.log('created触发');
        // console.log(this.$refs.oul,111);
      },
      beforeMount(){
        console.log('beforeMount触发');
        // console.log(this.$refs.oul,222);
      },
      mounted(){
        console.log('mounted触发');
        // console.log(this.$refs.oul,333);
      },
      beforeUpdate(){
        console.log('beforeUpdate触发');
      },
      updated(){
        console.log('updated触发');
        console.log(this.$refs.oul.children, 222);
      },
      beforeUnmount(){
        console.log('卸载之前-beforeUnmount');
      },
      unmounted(){
        console.log('实例已经卸载');
      }
    }
    app.component('HomePage', HomePage)
    app.mount("#app")
  </script>
</body>
</html>